<?php
namespace V4;
class C_PayConfig extends \ResourceClass{
    function __construct()
    {
        require_once (ROOT . 'lib/WxPay/WxPay.php');
    }
    public $isActive = true;
    public $remark = '支付配置信息';
    public function get(array $req, array $post, &$result)
    {
        try {
            /* 授权验证【开始】 */
            if (!isset($req['uid'])) {
                return 'require user id ';
            }
            if (!isset($req['userType'])) {
                return 'require user type';
            }
            if (!isset($req['k']) || !isset($req['t'])) {
                return 'data error';
            }
            $user_cls = \Biz\UserHandler::getById($req['userType'],$req['uid']);
            if(!is_object($user_cls) || $user_cls->getEnterpriseId() ==false){
                return 'data error';
            }
            $enterprise_id = $user_cls->getEnterpriseId();

            /* 授权验证*/
            if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'],$enterprise_id, $req['t'], $req['k']) == false) {
                return 'data illegal';
            }
            $wxPayConfig = \WxPay::getPayConfig($enterprise_id);
            $result['APPID'] = $wxPayConfig['pay_config']['APPID'];
            $result['APPSECRET'] = $wxPayConfig['pay_config']['APPSECRET'];
        } catch (Exception $e) {
            return $e->getMessage();
        }

    }
}